part of '../index.dart';

class Tools {
  static unfocus() {
    WidgetsBinding.instance.focusManager.primaryFocus?.unfocus();
  }

  static String dateFromMS(int? timestamp, [String pattern = 'yyyy-MM-dd']) {
    final dateTime = DateTime.fromMillisecondsSinceEpoch(timestamp ?? 0);
    return DateFormat(pattern).format(dateTime);
  }

  static String dateFromS(String? dateString, [String pattern = 'yyyy-MM-dd']) {
    var datetime = DateTime.parse(dateString ?? '0');
    return DateFormat(pattern).format(datetime);
  }

  static Future<void> copy(String? value) async {
    await Clipboard.setData(ClipboardData(text: value ?? ''));
    return;
  }

  static bool get isAr => Intl.defaultLocale == 'ar';

  static BorderRadiusGeometry messageRadius(bool isNow) {
    if (isAr) {
      return BorderRadius.only(
        topLeft: Radius.circular(isNow ? 0 : 10),
        topRight: Radius.circular(isNow ? 10 : 0),
        bottomLeft: const Radius.circular(10),
        bottomRight: const Radius.circular(10),
      );
    } else {
      return BorderRadius.only(
        topLeft: Radius.circular(isNow ? 10 : 0),
        topRight: Radius.circular(isNow ? 0 : 10),
        bottomLeft: const Radius.circular(10),
        bottomRight: const Radius.circular(10),
      );
    }
  }
}
